//
// mime_types.cpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include "MimeTypes.h"

namespace http
{
	namespace server
	{
		namespace mime_types
		{
			struct mapping
			{
				const char* extension;
				const char* mime_type;
			}
			// content type mapping
			mappings[] =
			{
				{ "gif", "image/gif" },
				{ "htm", "text/html" },
				{ "html", "text/html" },
				{ "jpg", "image/jpeg" },
				{ "png", "image/png" },
				{ "exe", "application/octet-stream"	},
				{ "zip", "application/x-zip-compressed" },
				{ "txt", "text / plain"}

			};

			/******************************************************************
			************
			* ++
			* Method name 	: extension to mime type
			* Description   : get mime type from file extension
			* Parameters    : none
			*
			* Global Variables
			*    Accessed   : none
			*    Modified   : none
			*
			* Return values : void
			*
			* Modifications  : Endless love
			* Description
			*
			* --
			*******************************************************************
			**********/
			std::string extension_to_type(const std::string& extension)
			{
				for (mapping m : mappings)
				{
					if (m.extension == extension)
					{
						return m.mime_type;
					}
				}

				return "application/octet-stream";
			}

		} // namespace mime_types
	} // namespace server
} // namespace http